﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Cit.CDE.Net.Service.ModuleFactory;
using Cit.CDE.Net.Module;
using System.Collections.Generic;
using Cit.CDE.Net.Module.Commons;
using cde.SystemCommon;
using Cit.CDE.Net.Service;
using System.Text;

using Module;


/// <summary>
/// Copyright (C)   jinggubang
/// FileName:        MsgView.aspx.cs           
/// Author :         wangbc
/// CDT:             2012-02-01           
/// Version:         1.0.0.0                
/// Depiction:       系统通知详细   
/// </summary>
public partial class main_admin_MsgView : UserControl.CommonPage
{
    /// <summary>
    /// 系统通知EM
    /// </summary>
    private CDEEntityManager em;
    /// <summary>
    /// 系统通知Entity
    /// </summary>
    private CDEEntity m_entity;
    /// <summary>
    /// 系统通知Entity名字
    /// </summary>    
    private const string EM_FULL_NAME = WEBConstants.EM_MSG_MANAGE;

    /// <summary>
    /// 页面初始化
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //系统通知ID
        string chkID = (string)Request.QueryString.Get("chkID");
        

        em = CDEEMFactory.getEMByFullName(EM_FULL_NAME);
        if (!Page.IsPostBack)
        {
            //ID不为空修改系统通知，否则新增系统通知
            if (chkID != "" && chkID != null)
            {
                //修改
                this.page_title.InnerText = "系统通知详细";
                CDESearchCriteria sc = new CDESearchCriteria(em);
                sc.addCondition("ID", chkID);
                List<CDEEntity> listEntity = CDEService.LoadEntities(em, sc);
                //系统通知ID是否存在
                if (listEntity.Count > 0)
                {
                    m_entity = listEntity[0];
                    m_entity.Operation = CDEDataOperation.UPDATE;
                }
                else
                {
                    m_entity = CDEEMServiceFactory.getEMService(em).CreateEntity();
                    m_entity.Operation = CDEDataOperation.INSERT;
                }
            }
            else
            {
                //新增
                this.page_title.InnerText = "系统通知新增";
                m_entity = CDEEMServiceFactory.getEMService(em).CreateEntity();
                m_entity.Operation = CDEDataOperation.INSERT;
                
            }
            Session["MENTITY"] = m_entity;
            //系统通知信息设值到页面
            this.setControls(m_entity, Resources.ResourceErrMsg.ResourceManager);
        }
        else
        {
            m_entity = (CDEEntity)Session["MENTITY"];
            //页面信息放入系统通知Entity
            this.setEntityFromRequest(m_entity, Request.Params);
        }

        //返回显示
        string viewType = Util.objectToString((string)Request.QueryString.Get("viewType"));
        if (viewType != "")
        {
            this.Button3.Visible = false;
        }
        else {
            this.Button3.Visible = true;
        }
    }
    
    /// <summary>
    /// 返回按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void cmdCancel_Click(object sender, EventArgs e)
    {
        if (Sel_MenuNode == null)
            return;
        StringBuilder url = new StringBuilder();
        url.Append("../admin/MsgListView.aspx?EM=");
        url.Append(EM_FULL_NAME);
        url.Append("&sel_menu_id=");
        url.Append(Sel_MenuNode.Attributes["id"].Value);
        url.Append("&IsBackSc=1");
        Response.Redirect(url.ToString());

    }
}
